package com.appbee.core.client.rpcfilter.filters;

import com.appbee.core.client.rpcfilter.RpcFilter;
import com.appbee.core.client.rpcfilter.RpcFilterChain;
import com.appbee.core.client.rpcfilter.callback.FilterCallback;

/**
 * 
 * @author jakob
 * 
 * 
 * 
 * @param <I>
 *            Input type
 * @param <R>
 *            Result type
 */
public class CancelSameValueFilter<I, R> implements RpcFilter<I, R>
{
	private I currentValue;

	public CancelSameValueFilter(I currentInput)
	{
		this.currentValue = currentInput;
	}

	@Override
	public void doFilter(I input, FilterCallback<R> callback, RpcFilterChain<I, R> chain)
	{
		if (input != null && !input.equals(currentValue))
		{
			currentValue = input;
			chain.doFilter(input, callback);
		}
		else
		{
			callback.onCancel(this);
		}
	}

}
